/*
 * @Descripttion: 
 * @Author: junhuafly
 * @Date: 2020-03-12 17:31:22
 * @LastEditors: junhuafly
 * @Email: junhuafly@163.com
 * @LastEditTime: 2020-03-12 18:41:39
 */
// components/replyInput/index.js
import {
  noteAPI
} from './../../api/note'
import {
  returnStatus
} from './../../utils/util'
Component({
  /**
   * 组件的属性列表
   */
  properties: {
    show: Boolean,
    subReply: Object,
    noteId: Number
  },
  observers: {},
  /**
   * 组件的初始数据
   */
  data: {
    showReply: false,
    replyVal: ''
  },

  /**
   * 组件的方法列表
   */
  methods: {
    onHideReplyMask() {
      this.setData({
        show: false
      })
    },
    bindReplyVal({
      detail
    }) {
      this.setData({
        replyVal: detail
      })
    },

    // 评论
    async replyAction() {
      const _this = this;
      const _ = await noteAPI.replyAction({
        replyContent: this.data.replyVal,
        ...(this.data.subReply && this.data.subReply.replyToId ? this.data.subReply : {
          noteId: this.data.noteId
        })
      })
      const res = await returnStatus(_)
      if (res) {
        this.setData({
          replyVal: ''
        })
        this.triggerEvent("replySuccess", res)
      }
    },
  }
})